package com.dev;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.Space;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import com.fb.FileBrowserPage;
import com.ima.ImageManipulationPage;
import com.ima.QuerySaveImage;
import com.log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import android.content.ClipData;
import android.view.WindowManager;
public final class GUI extends LinearLayout implements OnClickListener,OnLongClickListener,OnEditorActionListener,TextWatcher{
	public final static String browserHome="browser_home";
	public final static String browserNow="browser_now";
    public ActionMenu.QueryCreateFont qcf;
	public LinearLayout titlebar;
	public LinearLayout batch;
	public LinearLayout searchbar;
	public LinearLayout.LayoutParams titlebarlp;
	public LinearLayout.LayoutParams bottombarlp;
	public TabBar tabs;
	public static int borderWidth=2;
	public static int borderColor=0xff00bbff;
	public View tfNow=null;
	public IconView ivMenu,ivRW,ivSave,ivRefresh,ivChrome;
	public IconView ivInfo,ivQuit,ivInto,ivPR,ivSearch,ivBrowse;
	public IconView ivUndo,ivRedo,ivMore;
    public IconView icExpand,ivCut,icPaste,icCopy;
    public IconView icQuit;
	public IconView searchbar_quit,searchbar_menu;
	public IconView searchbar_next,searchbar_prev;
	public FrameLayout.LayoutParams pageLayoutParams;
	public TabOnClick TabOnClick=new TabOnClick();
	public DefaultPage defaultPage;
	public ExtraBarForIndentEditor ebi;
	public ExtraKey ek;
	public EditText searchbar_editor;
	public TextView status;
	public ConfirmRemoveDirectory confirmRemoveDirectory;
	public ConfirmFinishEditing confirmFinishEditing;
	public ConfirmRemoveEditorTab confirmRemoveEditorTab;
	public ConfirmRemoveTab confirmRemoveTab;
	public FileBrowserTabMenu fbtm;
	public AppListTabMenu appListTabMenu;
	public FrameLayout pageStub;
	public FileBrowserPage fileBrowserPage;
	public ShowImageDetails showImageDetails;
    public ShowSoftInput ssi;
	public WebBrowserPage webBrowserPage;
    public WindowManager.LayoutParams ebilp=new WindowManager.LayoutParams();
	public int titleIndex;
	public int bottomIndex;
	ScrollBar titlebarhsv;
	MainActivity ma;
	ActionMenu actionMenu;
	HorizontalScrollView hsv;
	QuerySettingsForCEditor qsfc;
    JavaEditorTab.Menu jetm;
    public QuerySaveImage querySaveImage;
	View tfNow_;
	public GUI(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(VERTICAL);
        icQuit=new IconView(ma);
        icQuit.setImageResource(R.drawable.ic_arrow_left);
        icQuit.setOnClickListener(this);
        icExpand=new IconView(ma);
        icExpand.setOnClickListener(this);
        icExpand.setImageResource(R.drawable.ic_arrow_expand_all);
        icExpand.setBackground(new Pressed());
        icCopy=new IconView(ma);
        icCopy.setImageResource(R.drawable.ic_content_copy);
        icCopy.setOnClickListener(this);
        icCopy.setBackground(new Pressed());
        icPaste=new IconView(ma);
        icPaste.setImageResource(R.drawable.ic_content_paste);
        icPaste.setOnClickListener(this);
        icPaste.setBackground(new Pressed());
        ivCut=new IconView(ma);
        ivCut.setImageResource(R.drawable.ic_content_cut);
        ivCut.setOnClickListener(this);
        ivCut.setBackground(new Pressed());
		ivRW=new IconView(ma);
        ivRW.setPadding(1,1,4,1);
        ivRW.setImageResource(R.drawable.ic_eye);
		ivRW.setOnClickListener(this);
		ivRW.setVisibility(GONE);
		ivSave=new IconView(ma){
            Paint icPaint=new Paint();
            int l,t,r,b;
            final int COLOR_FASTENER=0xff754464;
            @Override
            public void onDraw(Canvas cvs){
				int vw=getWidth();
				int vh=getHeight();
				int paddingh=vw/8;
                int paddingv=vh/8;
                int spaceHor=vw-paddingh*2;
                t=paddingv;
				b=vh-paddingv;
				l=(spaceHor-(b-t))/2+(b-t)*3/11;///
				r=vw-l;
                icPaint.setStrokeWidth(vh/15);
                Path path=new Path();
                path.moveTo(l,b);
                path.lineTo(l,t);
                path.lineTo(r-vw/8,t);
                path.lineTo(r,t+vw/8);
                path.lineTo(r,b);
                path.close();
                //cvs.drawColor(0x00ffffff);
                icPaint.setColor(MainActivity.CYAN);
                icPaint.setColorFilter(getColorFilter());
                int saved=cvs.saveLayer(0,0,cvs.getWidth(),cvs.getHeight(),null,Canvas.ALL_SAVE_FLAG);
                cvs.drawPath(path,icPaint);
                int ll,tt,rr,bb;
                ll=(r-l)/5+l;
                tt=(b-t)/4+t;
                rr=r-(r-l)/5;
                bb=tt+(b-t)/4;
                icPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
                cvs.drawRect(ll,tt,rr,bb,icPaint);
                icPaint.setXfermode(null);
                icPaint.setColor(COLOR_FASTENER);
                int li,ti,ri,bi;
                ti=tt;
                bi=bb;
                ri=rr-(r-rr)/2;
                li=ri-(bb-tt)/2;
                cvs.drawRect(li,ti,ri,bi,icPaint);
                cvs.restoreToCount(saved);
            }
        };
		ivSave.setVisibility(GONE);
		ivSave.setOnClickListener(this);
		ivSave.setOnLongClickListener(this);
		ivSearch=new IconView(ma);
		ivSearch.setImageResource(R.drawable.ic_search);
		ivSearch.setOnClickListener(this);
		ivSearch.setOnLongClickListener(this);
		ivRefresh=new IconView(ma);
		ivRefresh.setColorFilter(IconView.unable);
		ivRefresh.setOnClickListener(this);
		ivRefresh.setOnLongClickListener(this);
		ivRefresh.setImageResource(R.drawable.ic_file_refresh_outline);
		ivRefresh.setVisibility(GONE);
        ivBrowse=new IconView(ma);
		ivBrowse.setImageResource(R.drawable.folder);
		ivBrowse.setOnClickListener(this);
		ivChrome=new IconView(ma);
		ivChrome.setOnClickListener(this);
		ivChrome.setImageResource(R.drawable.ic_explorer);
		ivMenu=new IconView(ma);
		ivMenu.setImageResource(R.drawable.ic_menu);
		ivMenu.setOnClickListener(this);
        ivMore=new IconView(ma);
        ivMore.setOnClickListener(this);
        ivMore.setImageResource(R.drawable.ic_dots_vertical);
		ivPR=new IconView(ma);
		ivPR.setOnClickListener(this);
		ivPR.setImageResource(R.drawable.ic_pause);
		ivPR.setVisibility(View.GONE);
		ivInfo=new IconView(ma);
		ivInfo.setImageResource(R.drawable.ic_information_outline);
		ivInfo.setOnClickListener(this);
		ivInfo.setVisibility(View.GONE);
		ivQuit=new IconQuit(ma);
		ivQuit.setOnClickListener(this);
		ivQuit.setVisibility(GONE);
		ivInto=new IconInto(ma);
		ivInto.setOnClickListener(this);
		ivInto.setVisibility(View.GONE);
		ivUndo=new IconView(ma);
		ivUndo.setOnClickListener(this);
		ivUndo.setImageResource(R.drawable.back);
		ivRedo=new IconView(ma);
		ivRedo.setOnClickListener(this);
		ivRedo.setImageResource(R.drawable.forward);
		titlebarhsv=new ScrollBar(ma);
		titlebarhsv.setHorizontalScrollBarEnabled(false);
		titlebar=new LinearLayout(ma);
		titlebar.setOrientation(HORIZONTAL);
		titlebar.setFocusable(true);
		titlebar.setBackgroundColor(MainActivity.titlebarBackgroundColor);
		titlebar.addView(ivMenu);
		titlebar.addView(titlebarhsv,new LayoutParams(0,-1,1));
        titlebar.addView(ivMore);
        titlebarhsv.addView(ivInfo);
        titlebarhsv.addView(ivUndo);
        titlebarhsv.addView(ivRedo);
        titlebarhsv.addView(ivSearch);
        titlebarhsv.addView(ivRefresh);
        titlebarhsv.addView(ivRW);
        titlebarhsv.addView(ivSave);
        titlebarhsv.addView(ivPR);
        titlebarhsv.addView(ivInto);
        titlebarhsv.addView(ivQuit);
        titlebarhsv.addView(ivChrome);
        titlebarlp=new LinearLayout.LayoutParams(-1,ma.titlebarHeight);
        titlebar.setLayoutParams(titlebarlp);
		status=new TextView(ma);
        status.setGravity(Gravity.CENTER_VERTICAL|Gravity.LEFT);
        status.setTextColor(0xff000000);
        status.setTypeface(Typeface.MONOSPACE);
        status.setEllipsize(TextUtils.TruncateAt.START);
        status.setSingleLine();
		status.setVisibility(GONE);
		tabs=new TabBar(ma);
		tabs.ma=ma;
        
        ssi=new ShowSoftInput(ma);
        ssi.setOnClickListener(this);
		batch=new LinearLayout(ma);
        batch.setOrientation(0);
        batch.addView(icQuit);
        batch.addView(new Space(ma),new LinearLayout.LayoutParams(0,-1,1f));
		batch.addView(ssi);
        batch.addView(icExpand);
        batch.addView(ivCut);
        batch.addView(icPaste);
        batch.addView(icCopy);
		searchbar_quit=new IconView(ma);
		searchbar_quit.setImageResource(R.drawable.ic_quit_thin);
		searchbar_quit.setOnClickListener(this);
		searchbar_editor=new UnderlineSingleLineEditor(ma);
		searchbar_editor.setBackground(new ColorDrawable(0x00ffffff));
		searchbar_editor.setTextColor(0xff000000);
		searchbar_editor.setTypeface(Typeface.MONOSPACE);
		searchbar_editor.setTextSize(TypedValue.COMPLEX_UNIT_DIP,12);
		searchbar_editor.setSingleLine();
		searchbar_editor.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
		searchbar_editor.setGravity(Gravity.CENTER_VERTICAL);
		searchbar_editor.setPadding(9,0,9,0);
		searchbar_editor.setOnEditorActionListener(this);
		searchbar_editor.addTextChangedListener(this);
		searchbar_prev=new IconViewArrow(ma,true);
		searchbar_prev.setOnClickListener(this);
		searchbar_next=new IconViewArrow(ma,false);
		searchbar_next.setOnClickListener(this);
		searchbar_menu=new IconView(ma);
		searchbar_menu.setImageResource(R.drawable.ic_dots_vertical);
		searchbar_menu.setOnClickListener(this);
		searchbar=new LinearLayout(ma);
		searchbar.setOrientation(0);
		searchbar.setVisibility(GONE);
		searchbar.addView(searchbar_quit);
		searchbar.addView(searchbar_editor,new LayoutParams(0,-1,1f));
		searchbar.addView(searchbar_prev);
		searchbar.addView(searchbar_next);
		searchbar.addView(searchbar_menu);
		hsv=new HorizontalScrollView(ma);
		hsv.addView(tabs);
		//hsv.setBackgroundColor(0x77dec777);
		hsv.setHorizontalScrollBarEnabled(false);
		hsv.setFillViewport(false);
		ebi=new ExtraBarForIndentEditor(ma);
		ebi.setVisibility(GONE);
        ebilp.flags=ebilp.FLAG_LAYOUT_IN_SCREEN;
        ebilp.type=ebilp.TYPE_APPLICATION_SUB_PANEL;
        ebilp.gravity=Gravity.BOTTOM;
        ebilp.token=getWindowToken();
		ek=new ExtraKey(ma);
		defaultPage=new DefaultPage(ma);
		pageLayoutParams=new FrameLayout.LayoutParams(-1,-1);
		pageStub=new FrameLayout(ma);
		pageStub.addView(defaultPage,pageLayoutParams);
		
		bottombarlp=new LinearLayout.LayoutParams(-1,(int)(30*ma.dp));
		addView(titlebar,titlebarlp);
		addView(hsv,new LayoutParams(-1,(int)(25*ma.dp)));
		addView(status,-1,(int)(20*ma.dp));
		addView(pageStub,new LayoutParams(-1,0,1f));
		addView(ebi,-1,ebi.heightNow);
        actionMenu=new ActionMenu(ma);
		bottomIndex=4;
	}
	public void saveAllTab(){
		TabData.TabList tabList=new TabData.TabList();
		for(int index=0,count=ma.gui.tabs.getChildCount();index<count;index++){//
			View v=ma.gui.tabs.getChildAt(index);
			if(v instanceof FileBrowserTab){
				FileBrowserTab v_=(FileBrowserTab)v;
				if(v_.isNeedRemember()){
					if(v_.der==10){
						tabList.addTabInfo(new TabData.MediaImageInfo());
					}else if(v_.der==20){
						tabList.addTabInfo(new TabData.MediaAudioBrowser());
					}else if(v_.fbi!=null){
						tabList.addTabInfo(v_.fbi);
					}
				}
			}else if(v instanceof HtmlEditorTab){
				HtmlEditorTab h=(HtmlEditorTab)v;
				if(h.isNeedRemember()){
				}
			}else if(v instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)v;
				if(jet.isNeedRemember()){
					tabList.addTabInfo(jet.jei);
				}
			}else if(v instanceof AppListTab){
				AppListTab alt=(AppListTab)v;
				if(alt.isNeedRemember()){
					tabList.addTabInfo(new TabData.AppListInfo());
				}
			}else if(v instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)v;
				if(imt.isNeedRemember()){
					if(imt.im!=null)tabList.addTabInfo(imt.im);
				}
			}else if(v instanceof MediaAudioTab){
                MediaAudioTab mat=(MediaAudioTab)v;
                if(mat.isNeedRemember()){
                    tabList.addTabInfo(new TabData.MediaAudioBrowser());
                }
            }
		}
		ma.tabList=tabList;
		ma.tdm.updateSavedTabList(tabList);
	}
	void onTabSlipped(View v){
		if(v instanceof FileBrowserTab){
			FileBrowserTab fbt=(FileBrowserTab)v;
			try{
			if(confirmRemoveDirectory==null)confirmRemoveDirectory=new ConfirmRemoveDirectory(ma);
			confirmRemoveDirectory.show(fbt);
			}catch(Exception e){
				log.alert(e.toString());
			}
		}else if(v instanceof JavaEditorTab){
			JavaEditorTab jet=(JavaEditorTab)v;
			if(confirmRemoveEditorTab==null)confirmRemoveEditorTab=new ConfirmRemoveEditorTab(ma);
			if(ma.shr.getBoolean("remove_editor_tab_need_confirm",false)){
				if(jet.canSave)confirmRemoveEditorTab.show(jet);
			}else{
				confirmRemoveEditorTab.show(jet);
			}
		}else{
			if(confirmRemoveTab==null)confirmRemoveTab=new ConfirmRemoveTab(ma);
			confirmRemoveTab.show(v);
		}
	}
	public void removeTab(View tab){
		if(tab==tfNow){
			for(int index=0,count=tabs.getChildCount();true;index++){
				if(index<count){
					View v=tabs.getChildAt(index);
					if(v==tab){
						tabs.removeView(tab);
						if(index<tabs.getChildCount()){
							v=tabs.getChildAt(index);
							TabOnClick.onClick(v);
						}else if(--index>=0){
							v=tabs.getChildAt(index);
							TabOnClick.onClick(v);
						}else{
							TabOnClick.onClick(null);
						}
						return;
					}
				}else{
					log.alert("Exception:","Remove a tab,but this view not found in tab bar");
					break;
				}
			}
		}else{
			tabs.removeView(tab);
		}
	}
	int selectionStartSaved;
	int selectionEndSaved;
	int selectionStart;
	int selectionEnd;
	@Override
	public boolean onEditorAction(TextView textView, int p, KeyEvent keyEvent) {
		if(textView==searchbar_editor){
			String userinput=textView.getText().toString();
			final String notFound="找不到匹配的文本";
			if(tfNow instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)tfNow;
				JavaIndentEditor jie=jet.jep.jie;
				StringBuilder text=jie.text;
				int length=jie.text.length();
				outmost:
				for(int index=jie.selectionStart;true;index++){
					if(index<length){
						for(int offs=0;true;offs++){
							if(offs<userinput.length()){
								int index_=index+offs;
								if(index_<length){//finding usrinput
									char c1=text.charAt(index_);
									char c2=userinput.charAt(offs);
									if(c1!=c2)break;
								}else{//usrinput not found 
									selectionStart=-1;
									textView.setTextColor(0xff770000);
									Toast.makeText(ma,notFound,0).show();
									break outmost;
								}
							}else{//userinput is found;
								selectionStart=index;
								selectionEnd=index+userinput.length();
								jie.selectionStart=selectionStart;
								jie.selectionEnd=selectionEnd;
								jie.showSelection();
								jie.invalidate();
								textView.setTextColor(0xff000000);
								break outmost;
							}
						}
					}else{//usrinput not found 
						selectionStart=-1;
						textView.setTextColor(0xffff0000);
						Toast.makeText(ma,notFound,0).show();
						break;
					}
				}
			}
		}
		return true;
	}
	@Override
	public void onTextChanged(CharSequence charSequence, int p, int p1, int p2) {
	}
	@Override
	public void afterTextChanged(Editable editable) {
		if(searchbar_editor.isShown()){
			String userinput=editable.toString();
			if(userinput.isEmpty())return;
			if(tfNow instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)tfNow;
				JavaIndentEditor jie=jet.jep.jie;
				StringBuilder text=jie.text;
				int length=text.length();
				outmost:
				for(int index=0;true;index++){
					if(index<length){
						for(int offs=0;true;offs++){
							if(offs<userinput.length()){
								int index_=index+offs;
								if(index_<length){//finding usrinput
									char c1=text.charAt(index_);
									char c2=userinput.charAt(offs);
									if(c1!=c2)break;
								}else{//usrinput not found 
									selectionStart=-1;
									searchbar_editor.setTextColor(0xff770000);
									break outmost;
								}
							}else{//userinput is found;
								selectionStart=index;
								selectionEnd=index+userinput.length();
								jie.selectionStart=selectionStart;
								jie.selectionEnd=selectionEnd;
								jie.showSelection();
								jie.invalidate();
								searchbar_editor.setTextColor(0xff000000);
								break outmost;
							}
						}
					}else{//usrinput not found 
						selectionStart=-1;
						searchbar_editor.setTextColor(0xffff0000);
						break;
					}
				}
			}
		}
	}
	@Override
	public void beforeTextChanged(CharSequence charSequence, int p, int p1, int p2) {
	}
	@Override
	public void onClick(View v) {
        if(v==icCopy){
            removeViewAt(titleIndex);
            addView(titlebar,titleIndex,titlebarlp);
            if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                CEditorPage cep=cet.cep;
                String text=cep.cie.text.substring(cep.cie.selectionStart,cep.cie.selectionEnd);
                ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                ma.cm.setPrimaryClip(cd);
            }else if(tfNow instanceof FileBrowserTab){
                FileBrowserTab fbt=(FileBrowserTab)tfNow;
                FileBrowserPage fbp=fbt.fileBrowserPage;
                if(fbp.dyn==1){
                    String text=new String(fbp.ie.text,fbp.ie.selectionStart,fbp.ie.selectionEnd);
                    ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                    ma.cm.setPrimaryClip(cd);
                }else if(fbp.dyn==2){
                    String text=new String(fbp.hie.text,fbp.hie.selectionStart,fbp.hie.selectionEnd);
                    ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                    ma.cm.setPrimaryClip(cd);
                }
            }else if(tfNow instanceof JavaEditorTab){
                JavaEditorTab jet=(JavaEditorTab)tfNow;
                JavaEditorPage jep=jet.jep;
                String text=jep.jie.text.substring(jep.jie.selectionStart,jep.jie.selectionEnd);
                ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                ma.cm.setPrimaryClip(cd);
            }else{
                View focused=findFocus();
                if(focused!=null){
                    if(focused instanceof TextView){
                        TextView tv=(TextView)focused;
                        CharSequence text=tv.getText().subSequence(tv.getSelectionStart(),tv.getSelectionEnd());
                        ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                        ma.cm.setPrimaryClip(cd);
                    }
                }
            }
        }else if(v==icPaste){
            if(ma.cm.hasPrimaryClip()){
                ClipData primary=ma.cm.getPrimaryClip();
                if(tfNow instanceof CEditorTab){
                    CEditorTab cet=(CEditorTab)tfNow;
                    CEditorPage cep=cet.cep;
                    cep.cie.commitText(primary.getItemAt(0).getText().toString());
                }else if(tfNow instanceof FileBrowserTab){
                    FileBrowserTab fbt=(FileBrowserTab)tfNow;
                    FileBrowserPage fbp=fbt.fileBrowserPage;
                    if(fbp.dyn==1){
                        fbp.ie.commitText(primary.getItemAt(0).getText().toString());
                    }else if(fbp.dyn==2){
                        fbp.hie.commitText(primary.getItemAt(0).getText().toString());
                    }
                }
            }
        }else if(v==ivCut){
            removeViewAt(titleIndex);
            addView(titlebar,titleIndex,titlebarlp);
            if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                CEditorPage cep=cet.cep;
                int a=cep.cie.selectionStart,b=cep.cie.selectionEnd;
                ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,cep.cie.text.substring(a,b));
                ma.cm.setPrimaryClip(cd);
                cep.cie.commitText(null);
            }else if(tfNow instanceof FileBrowserTab){
                FileBrowserTab fbt=(FileBrowserTab)tfNow;
                FileBrowserPage fbp=fbt.fileBrowserPage;
                if(fbp.dyn==1){//opend a text file
                    IndentEditor ie=fbp.ie;
                    int a=Math.min(ie.selectionStart,ie.selectionEnd);
                    int b=Math.max(ie.selectionStart,ie.selectionEnd);
                    ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,new String(ie.text,a,b-a));
                    ie.commitText(null);
      
                    ma.cm.setPrimaryClip(cd);
                }else if(fbp.dyn==2){
                    HtmlIndentEditor hie=fbp.hie;
                    int a=Math.min(hie.selectionStart,hie.selectionEnd);
                    int b=Math.max(hie.selectionStart,hie.selectionEnd);
                    ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,new String(hie.text,a,b-a));
                    hie.commitText(null);
                    ma.cm.setPrimaryClip(cd);
                }
            }else if(tfNow instanceof JavaEditorTab){
                JavaEditorTab jet=(JavaEditorTab)tfNow;
                JavaEditorPage jep=jet.jep;
                JavaIndentEditor jie=jep.jie;
                String text=jie.text.substring(jie.selectionStart,jie.selectionEnd);
                ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                ma.cm.setPrimaryClip(cd);
                jie.commitText(null);
            }else{
                View focused=findFocus();
                if(focused instanceof TextView){
                    TextView tv=(TextView)focused;
                    int a=tv.getSelectionStart(),b=tv.getSelectionEnd();
                    CharSequence text=tv.getText().subSequence(a,b);
                    tv.getEditableText().delete(a,b);
                    ClipData cd=ClipData.newPlainText(MainActivity.CLIPBOARD_TAG,text);
                    ma.cm.setPrimaryClip(cd);
                }
            }
        }else if(v==icExpand){
            
        }else if(v==icQuit){
            removeViewAt(titleIndex);
            addView(titlebar,titleIndex,titlebarlp);
            if(tfNow instanceof FileBrowserTab){
                FileBrowserTab fbt=(FileBrowserTab)tfNow;
                FileBrowserPage fbp=fbt.fileBrowserPage;
            }
        }else if(v==ivMenu){//onClick
			actionMenu.show();
		}else if(v==ivQuit){//onClick
			ma.imm.hideSoftInputFromInputMethod(this.getWindowToken(),0);
            ebi.setVisibility(GONE);
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(VISIBLE);
				if(fbp.dyn==1){//edit text file
					ivRefresh.setVisibility(GONE);
					ivRW.setVisibility(GONE);
					ivInfo.setVisibility(GONE);
					ivSave.setVisibility(GONE);
                    removeViewAt(titleIndex);
                    addView(titlebar,titleIndex,titlebarlp);
					fbp.ie.setVisibility(GONE);
					fbp.dlv.setVisibility(VISIBLE);
					fbp.fn.setVisibility(VISIBLE);
					fbp.toolsbar.setVisibility(VISIBLE);
                    ma.imm.hideSoftInputFromWindow(getWindowToken(),0);
				}else if(fbp.dyn==2){//edit html file
					fbp.hie.setVisibility(GONE);
					fbp.dlv.setVisibility(VISIBLE);
					fbp.fn.setVisibility(VISIBLE);
					fbp.toolsbar.setVisibility(VISIBLE);
					ivInfo.setVisibility(GONE);
					ivRW.setVisibility(GONE);
					ivSave.setVisibility(GONE);
					ivRefresh.setVisibility(GONE);
					status.setVisibility(GONE);
					ivPR.setVisibility(GONE);
                    ma.imm.hideSoftInputFromWindow(getWindowToken(),0);
				}else if(fbp.dyn==3){
					if(fbp.hb.getVisibility()==VISIBLE){
						ivRefresh.setVisibility(GONE);
						ivRW.setVisibility(View.GONE);
						ivInfo.setVisibility(View.GONE);
						ivSave.setVisibility(View.GONE);
						ivPR.setVisibility(View.GONE);
						removeViewAt(titleIndex);
                        addView(titlebar,titleIndex,titlebarlp);
						if(fbp.hie!=null)fbp.hie.setVisibility(View.GONE);
						fbp.hb.setVisibility(View.GONE);
						fbp.dlv.setVisibility(View.VISIBLE);
						fbp.fn.setVisibility(View.VISIBLE);
						fbp.toolsbar.setVisibility(View.VISIBLE);
						if(fbp.ie!=null)fbp.ie.setVisibility(View.GONE);
					}
                    ma.imm.hideSoftInputFromWindow(getWindowToken(),0);
				}else if(fbp.dyn==4){
					if(fbp.hie.getVisibility()==VISIBLE){
						ivInfo.setVisibility(GONE);
						ivRW.setVisibility(GONE);
						ivSave.setVisibility(GONE);
						ivRefresh.setVisibility(GONE);
						status.setVisibility(GONE);
						ivPR.setVisibility(GONE);
						ebi.setVisibility(GONE);
						fbp.fn.setVisibility(VISIBLE);
						fbp.toolsbar.setVisibility(VISIBLE);
						fbp.dlv.setVisibility(VISIBLE);
						fbp.hie.setVisibility(GONE);
						fbp.view=fbp.hie;
					}else if(fbp.hb.getVisibility()==VISIBLE){
						fbp.hb.setVisibility(GONE);
						fbp.dlv.setVisibility(VISIBLE);
						fbp.fn.setVisibility(VISIBLE);
						fbp.toolsbar.setVisibility(VISIBLE);
						fbp.view=fbp.hb;
						ivPR.setVisibility(GONE);
						ivInfo.setVisibility(GONE);
					}
                    ma.imm.hideSoftInputFromWindow(getWindowToken(),0);
				}else if(fbp.dyn==11){
					ivRefresh.setVisibility(GONE);
					ivRW.setVisibility(View.GONE);
					ivInfo.setVisibility(View.GONE);
					ivSave.setVisibility(View.GONE);
					ivPR.setVisibility(View.GONE);
					removeViewAt(titleIndex);
                    addView(titlebar,titleIndex,titlebarlp);
					if(fbp.hie!=null)fbp.hie.setVisibility(View.GONE);
					fbp.hb.setVisibility(View.GONE);
					fbp.dlv.setVisibility(View.VISIBLE);
					fbp.fn.setVisibility(GONE);
					if(fbp.ie!=null)fbp.ie.setVisibility(View.GONE);
				}else if(fbp.dyn==12){
					ivRefresh.setVisibility(GONE);
					ivRW.setVisibility(GONE);
					ivInfo.setVisibility(GONE);
					ivSave.setVisibility(GONE);
					removeViewAt(titleIndex);
                    addView(titlebar,titleIndex,titlebarlp);
					fbp.ie.setVisibility(GONE);
					fbp.dlv.setVisibility(VISIBLE);
				}
			}else if(tfNow instanceof JavaEditorTab){
				//JavaEditorTab jet=(JavaEditorTab)tfNow;
			}
		}else if(v==ivInto){//onClick
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				if(fbp.dyn==1){
					ivQuit.setVisibility(View.VISIBLE);
					ivInto.setVisibility(View.GONE);
					fbp.dlv.setVisibility(View.GONE);
					fbp.fn.setVisibility(View.GONE);
                    fbp.ie.setVisibility(View.VISIBLE);
					if(fbp.hie!=null)fbp.hie.setVisibility(View.GONE);
					if(fbp.hb!=null)fbp.hb.setVisibility(View.GONE);
					fbp.toolsbar.setVisibility(View.GONE);
					if(fbp.hb!=null)fbp.hb.setVisibility(View.GONE);
					if(fbp.editorCanSave){
                        ivRefresh.setColorFilter(null);
                        ivSave.setColorFilter(null);
                    }else{
                        ivRefresh.setColorFilter(IconView.unable);
                        ivSave.setColorFilter(IconView.unable);
                    }
					ivRefresh.setVisibility(View.VISIBLE);
					ivRW.setVisibility(View.VISIBLE);
					ivInfo.setVisibility(View.VISIBLE);
					ivSave.setVisibility(View.VISIBLE);
					ivPR.setVisibility(View.GONE);
                    if(fbp.ie.canEdit){
                        ivRW.setImageResource(R.drawable.ic_lead_pencil);
                    }else{
                        ivRW.setImageResource(R.drawable.ic_eye);
                    }
				}else if(fbp.dyn==2){
					ivQuit.setVisibility(View.VISIBLE);
					ivInto.setVisibility(View.GONE);
					fbp.dlv.setVisibility(View.GONE);
					fbp.fn.setVisibility(View.GONE);
					if(fbp.hie!=null)fbp.hie.setVisibility(View.VISIBLE);
					fbp.toolsbar.setVisibility(View.GONE);
					if(fbp.hb!=null)fbp.hb.setVisibility(View.GONE);
					if(fbp.ie!=null)fbp.ie.setVisibility(View.GONE);
					ivQuit.setVisibility(View.VISIBLE);
					ivInto.setVisibility(View.GONE);
					ivRefresh.setVisibility(View.VISIBLE);
					ivRW.setVisibility(View.VISIBLE);
					ivInfo.setVisibility(View.VISIBLE);
					ivSave.setVisibility(View.VISIBLE);
					ivPR.setVisibility(View.VISIBLE);
					ivPR.setImageResource(R.drawable.ic_play);
				}else if(fbp.dyn==3||fbp.dyn==11){//for example,play music with webView,dont show editor at this time
					fbp.dlv.setVisibility(View.GONE);
					fbp.fn.setVisibility(View.GONE);
					if(fbp.hie!=null)fbp.hie.setVisibility(View.GONE);
					fbp.toolsbar.setVisibility(View.GONE);
					fbp.hb.setVisibility(View.VISIBLE);
					ivQuit.setVisibility(View.VISIBLE);
					ivInto.setVisibility(View.GONE);
					ivRefresh.setVisibility(View.GONE);
					ivRW.setVisibility(View.GONE);
					ivInfo.setVisibility(View.GONE);
					ivSave.setVisibility(View.GONE);
					ivPR.setVisibility(View.GONE);
				}else if(fbp.dyn==4){
					ivInto.setVisibility(View.GONE);
					ivQuit.setVisibility(View.VISIBLE);
					ivInfo.setVisibility(View.VISIBLE);
					ivRW.setImageResource(R.drawable.ic_lead_pencil);
					ivRW.setVisibility(View.VISIBLE);
					ivSave.setColorFilter(IconView.unable);
					ivSave.setVisibility(View.VISIBLE);
					ivRefresh.setColorFilter(IconView.unable);
					ivRefresh.setVisibility(View.VISIBLE);
					status.setText(fbp.file.getAbsolutePath());
					ivPR.setVisibility(View.VISIBLE);
					ivPR.setImageResource(R.drawable.ic_play);
					ebi.setVisibility(VISIBLE);
					fbp.dlv.setVisibility(View.GONE);
					fbp.fn.setVisibility(View.GONE);
					fbp.toolsbar.setVisibility(View.GONE);
					fbp.hie.setVisibility(VISIBLE);
				}
			}
		}else if(v==ivSave){//onClick
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				if(fbp.dyn==1){
                    if(fbp.editorCanSave){
                        IndentEditor ie=fbp.ie;
                        try{
                            FileWriter fw=new FileWriter(fbp.file);
                            fw.write(ie.text);
                            fw.close();
                            fbp.editorCanSave=false;
                            ivRefresh.setColorFilter(IconView.unable);
                            ivRefresh.invalidate();
                            ivSave.setColorFilter(IconView.unable);
                            ivSave.invalidate();
                            Toast.makeText(ma,"已保存",0).show();
                        }catch(Exception e){
                            log.alert(e.toString());
                        }
                    }
                }else if(fbp.dyn==4){//editting svg file
					if(!fbp.editorCanSave){
						return;
					}
					if(fbp.hie!=null&&fbp.hie.getVisibility()==VISIBLE){
						HtmlIndentEditor ie=fbp.hie;
						try{
							FileWriter fw=new FileWriter(fbp.file,false);
							fw.write(ie.text);
							fw.close();
							fbp.editorCanSave=false;
							fbt.setTextColor(fbt.textColorDefault);
							ivSave.setColorFilter(IconView.unable);
							ivSave.invalidate();
							ivRefresh.setColorFilter(IconView.unable);
							ivRefresh.invalidate();
							Toast.makeText(ma,"已保存",0).show();
						}catch(Exception e){
							log.alert(e.toString());
						}
					}
				}
			}else if(tfNow instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)tfNow;
				if(jet.canSave){
					try{
						FileWriter fw=new FileWriter(jet.jei.src,false);
						fw.write(jet.jep.jie.text.toString());
						fw.close();
						jet.canSave=false;
						jet.setTextColor(jet.textColorDefault);
						ivSave.setColorFilter(IconView.unable);
						ivSave.invalidate();
						ivRefresh.setColorFilter(IconView.unable);
						ivRefresh.invalidate();
						Toast.makeText(ma,"已保存",0).show();
					}catch(Exception e){
						log.alert(e.toString());
					}
				}
			}else if(tfNow instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)tfNow;
				ImageManipulationPage imp=imt.imp;
				if(imt.im==null){
					if(querySaveImage==null)querySaveImage=new QuerySaveImage(ma);
					querySaveImage.show(0,imt);
				}else{
					if(imp.canSave){
						try{
							FileOutputStream fos=new FileOutputStream(imt.im.src);
							imp.cv.image.compress(Bitmap.CompressFormat.PNG,100,fos);
							Toast.makeText(ma,"已保存",0).show();
							imp.canSave=false;
							ivSave.setColorFilter(IconView.unable);
							ivSave.invalidate();
							ivRefresh.setColorFilter(IconView.unable);
							ivRefresh.invalidate();
						}catch(Exception e){
							log.alert(e.toString());
						}
					}else{
						Toast.makeText(ma,"图像未变更",0).show();
					}
				}
			}else if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                CEditorPage cep=cet.cep;
                if(cet.canSave){
                    if(cep.cie.canEdit){
                        try{
                            FileWriter fw=new FileWriter(cet.ce.src);
                            fw.write(cep.cie.text.toString());
                            fw.close();
                            ivSave.setColorFilter(IconView.unable);
                            ivSave.invalidate();
                            ivRefresh.setColorFilter(IconView.unable);
                            ivRefresh.invalidate();
                            cet.canSave=false;
                            cet.setTextColor(cet.textColorDefault);
                            Toast.makeText(ma,"文件已保存",0).show();
                        }catch(Exception e){
                            log.alert("On save text to file",e.toString());
                        }
                    }
                    
                }else if(cep.cie.canEdit){
                    Toast.makeText(ma,"代码未变更",0).show();
                }else{
                    Toast.makeText(ma,"只读",0).show();
                }
            }
		}else if(v==ivRefresh){//onClick
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				if(fbp.dyn==1){
					IndentEditor ie=fbp.ie;
					if(ie.canEdit){
						if(fbp.editorCanSave){
							try{
								FileReader fr=new FileReader(fbp.file);
								int i=fr.read();
								StringBuilder sb=new StringBuilder();
								while(i>=0){
									sb.append((char)i);
									i=fr.read();
								}
								String content=sb.toString();
								ie.letText(content.toCharArray());
								ie.invalidate();
								fbp.editorCanSave=false;
								fbt.setTextColor(fbt.textColorDefault);
								ivRefresh.setColorFilter(IconView.unable);
								ivRefresh.invalidate();
								ivSave.setColorFilter(IconView.unable);
								ivSave.invalidate();
								Toast.makeText(ma,"已刷新",0).show();
							}catch(Exception e){
								log.alert(e.toString());
							}
						}
					}
				}else if(fbp.dyn==2){
					HtmlIndentEditor ie=fbp.hie;
					if(ie.canEdit){
						if(fbp.editorCanSave){
							try{
								FileReader fr=new FileReader(fbp.file);
								int i=fr.read();
								StringBuilder sb=new StringBuilder();
								while(i>=0){
									sb.append((char)i);
									i=fr.read();
								}
								String content=sb.toString();
								fbp.hie.letText(content.toCharArray());
								fbp.hie.invalidate();
								fbp.editorCanSave=false;
								fbt.setTextColor(fbt.textColorDefault);
								ivRefresh.setColorFilter(IconView.unable);
								ivRefresh.invalidate();
								ivSave.setColorFilter(IconView.unable);
								ivSave.invalidate();
								fbp.editorCanSave=false;
								Toast.makeText(ma,"已刷新",0).show();
							}catch(Exception e){
								log.alert(e.toString());
							}
						}
					}
				}else if(fbp.dyn==4){//editting svg file 
					HtmlIndentEditor ie=fbp.hie;
					if(fbp.editorCanSave){
						if(ie.canEdit){
							try{
								FileReader fr=new FileReader(fbp.file);
								int i=fr.read();
								StringBuilder sb=new StringBuilder();
								while(i>=0){
									sb.append((char)i);
									i=fr.read();
								}
								String content=sb.toString();
								fbp.hie.letText(content.toCharArray());
								fbp.hie.invalidate();
								fbp.editorCanSave=false;
								fbt.setTextColor(fbt.textColorDefault);
								ivRefresh.setColorFilter(IconView.unable);
								ivRefresh.invalidate();
								ivSave.setColorFilter(IconView.unable);
								ivSave.invalidate();
								fbp.editorCanSave=false;
								Toast.makeText(ma,"已刷新",0).show();
							}catch(Exception e){
								log.alert(e.toString());
							}
						}
					}
				}
			}else if(tfNow instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)tfNow;
				try{
					FileReader fr=new FileReader(jet.jei.src);
					int i=fr.read();
					StringBuilder sb=new StringBuilder();
					while(i>=0){
						sb.append((char)i);
						i=fr.read();
					}
					jet.jep.jie.letText(sb);
					jet.jep.jie.invalidate();
					jet.canSave=false;
					jet.setTextColor(jet.textColorDefault);
					Toast.makeText(ma,"已刷新",0).show();
					ivSave.setColorFilter(IconView.unable);
					ivSave.invalidate();
					ivRefresh.setColorFilter(IconView.unable);
					ivRefresh.invalidate();
				}catch(Exception e){
					log.alert(e.toString());
				}
			}else if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                CEditorPage cep=cet.cep;
                if(cet.canSave){
                    if(cep.cie.canEdit){
                        try{
                            FileReader fr=new FileReader(cet.ce.src);
                            StringBuilder sb=cep.cie.text;
                            sb.setLength(0);
                            int i=fr.read();
                            while(i>=0){
                                sb.append((char)i);
                                i=fr.read();
                            }
                            fr.close();
                            cep.cie.letText(sb);
                            cet.canSave=false;
                            cet.setTextColor(cet.textColorDefault);
                            ivRefresh.setColorFilter(IconView.unable);
                            ivRefresh.invalidate();
                            ivSave.setColorFilter(IconView.unable);
                            ivSave.invalidate();
                            Toast.makeText(ma,"已刷新",0).show();
                        }catch(Exception e){
                            log.alert("On reload text from file",e.toString());
                        }
                    }else{
                        Toast.makeText(ma,"只读",0).show();
                    }
                }
            }
		}else if(v==ivPR){//onClick
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				if(fbp.dyn==2){
					if(fbp.hie.getVisibility()==VISIBLE){
						ivPR.setImageResource(R.drawable.ic_pause);
						if(fbp.hb==null){fbp.hb=new HtmlBrowser(ma);fbp.addView(fbp.hb,fbp.pageLayoutParams);}
						fbp.hie.setVisibility(GONE);
						fbp.hb.setVisibility(VISIBLE);
						fbp.hb.webView.loadUrl("file://"+fbp.file.getAbsolutePath());
						ebi.setVisibility(GONE);
						ivSave.setVisibility(GONE);
						ivRefresh.setVisibility(GONE);
						ivRW.setVisibility(GONE);
					}else if(fbp.hb!=null&&fbp.hb.getVisibility()==VISIBLE){
						ivPR.setImageResource(R.drawable.ic_play);
						fbp.hb.setVisibility(GONE);
						fbp.hie.setVisibility(VISIBLE);
						ebi.setVisibility(VISIBLE);
						ivSave.setVisibility(VISIBLE);
						ivRefresh.setVisibility(VISIBLE);
						ivRW.setVisibility(VISIBLE);
					}
				}else if(fbp.dyn==4){
					if(fbp.hie.getVisibility()==VISIBLE){
						ivPR.setImageResource(R.drawable.ic_pause);
						if(fbp.hb==null){fbp.hb=new HtmlBrowser(ma);fbp.addView(fbp.hb,fbp.pageLayoutParams);}
						fbp.hie.setVisibility(GONE);
						fbp.hb.setVisibility(VISIBLE);
						fbp.hb.webView.loadUrl("file://"+fbp.file.getAbsolutePath());
						ebi.setVisibility(GONE);
						ivSave.setVisibility(GONE);
						ivRefresh.setVisibility(GONE);
						ivRW.setVisibility(GONE);
					}else if(fbp.hb!=null&&fbp.hb.getVisibility()==VISIBLE){
						ivPR.setImageResource(R.drawable.ic_play);
						fbp.hb.setVisibility(GONE);
						fbp.hie.setVisibility(VISIBLE);
						ebi.setVisibility(VISIBLE);
						ivSave.setVisibility(VISIBLE);
						ivRefresh.setVisibility(VISIBLE);
						ivRW.setVisibility(VISIBLE);
					}
				}
			}
		}else if(v==ivSearch){//onClick
			
            removeViewAt(titleIndex);
            addView(searchbar,titleIndex,titlebarlp);
			searchbar_editor.setText(null);
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
			}else if(tfNow instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)tfNow;
				JavaIndentEditor jie=jet.jep.jie;
				selectionStartSaved=jie.selectionStart;
				selectionEndSaved=jie.selectionEnd;
			}else if(tfNow instanceof HtmlEditorTab){
			}else if(tfNow instanceof XmlEditorTab){
			}else if(tfNow instanceof TextEditorTab){
			}
		}else if(v==ivBrowse){//onClick
			if(fileBrowserPage==null){
				fileBrowserPage=new FileBrowserPage(ma);
				String homePath=ma.shr.getString(browserHome,null);
				String nowPath=ma.shr.getString(browserNow,null);
				if(homePath==null){
					fileBrowserPage.home=Environment.getExternalStorageDirectory();
					ma.shr.edit().putString(browserHome,fileBrowserPage.home.getAbsolutePath()).apply();
				}else{
					File f=new File(homePath);
					if(f.exists()){
						if(f.isDirectory()){
							if(f.canRead()){
								fileBrowserPage.home=f;
							}else{
								Toast.makeText(ma,"can not reveal given directory,is not readable:"+homePath,0).show();
							}
						}else{
							Toast.makeText(ma,"can not reveal given path,is a regular file:"+homePath,0).show();
						}
					}else{
						Toast.makeText(ma,"directory not found:"+homePath,0).show();
					}
					if(fileBrowserPage.home==null){
						File parent=f.getParentFile();
						while(true){
							if(parent!=null){
								if(parent.canRead()){
									fileBrowserPage.home=parent;
									break;
								}
								parent=parent.getParentFile();
							}else{
								fileBrowserPage.home=Environment.getExternalStorageDirectory();
								break;
							}
						}
					}
				}
				if(nowPath==null){
					fileBrowserPage.letDir(fileBrowserPage.home);
				}else{
					File f=new File(nowPath);
					fileBrowserPage.letDir(f);
				}
			}
			if(fileBrowserPage.isShown()){
				ivBrowse.setImageResource(R.drawable.folder);
				TabOnClick.onClick(tfNow_);
				SharedPreferences.Editor edit= ma.shr.edit();
				edit.putString(browserHome,fileBrowserPage.home.getAbsolutePath());
				edit.apply();
			}else{
				pageStub.removeViewAt(0);
				pageStub.addView(fileBrowserPage,pageLayoutParams);
				ivBrowse.setImageResource(R.drawable.folder_open);
				tfNow_=tfNow;
				if(tfNow!=null){
					TabBar.Tab t=(TabBar.Tab)tfNow;
					t.letUnderline(false);
					tfNow=null;
				}
			}
		}else if(v==ivInfo){//onClick
			if(tfNow instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)tfNow;
				if(showImageDetails==null)showImageDetails=new ShowImageDetails(ma);
				showImageDetails.show(imt);
			}else if(tfNow instanceof FileBrowserTab){
                FileBrowserTab fbt=(FileBrowserTab)tfNow;
                FileBrowserPage fbp=fbt.fileBrowserPage;
                if(fbp.file!=null){
                    if(ma.fileDetails==null){ma.fileDetails=new ShowFileDetails(ma);}
                    ma.fileDetails.show(fbp.file,fbp);
                }
            }
		}else if(v==ivChrome){//onClick
			if(webBrowserPage==null){
				webBrowserPage=new WebBrowserPage(ma);
				webBrowserPage.webView.loadUrl(webBrowserPage.bing);
				pageStub.removeViewAt(0);
				pageStub.addView(webBrowserPage,0,pageLayoutParams);
				ivInto.setVisibility(GONE);
				ivQuit.setVisibility(GONE);
				ivSave.setVisibility(GONE);
				ivRW.setVisibility(GONE);
				ivRefresh.setVisibility(GONE);
				ivUndo.setVisibility(GONE);
				ivRedo.setVisibility(GONE);
			}else{
				View page=pageStub.getChildAt(0);
				if(page==webBrowserPage){
					View vv=tfNow;
					tfNow=null;
					TabOnClick.onClick(vv);
				}else{
					pageStub.removeViewAt(0);
					pageStub.addView(webBrowserPage,0,pageLayoutParams);
					ivInto.setVisibility(GONE);
					ivQuit.setVisibility(GONE);
					ivSave.setVisibility(GONE);
					ivRW.setVisibility(GONE);
					ivRefresh.setVisibility(GONE);
					ivUndo.setVisibility(GONE);
					ivRedo.setVisibility(GONE);
				}
			}
		}else if(v==ivRW){//onClick
			if(tfNow instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)tfNow;
				ImageManipulationPage imp=imt.imp;
				if(imp.editMode){
					imp.editMode=false;
					imp.cv.invalidate();
					ivRW.setImageResource(R.drawable.ic_eye);
				}else{
					imp.editMode=true;
					imp.cv.invalidate();
					ivRW.setImageResource(R.drawable.ic_lead_pencil);
				}
			}else if(tfNow instanceof FileBrowserTab){
                if(tfNow instanceof FileBrowserTab){
                    FileBrowserTab fbt=(FileBrowserTab)tfNow;
                    FileBrowserPage fbp=fbt.fileBrowserPage;
                    if(fbp.dyn==1){
                        IndentEditor ie=fbp.ie;
                        if(ie.canEdit){
                            ie.canEdit=false;
                            ie.canShowSoftInput=false;
                            ivRW.setImageResource(R.drawable.ic_eye);
                            ma.imm.hideSoftInputFromWindow(ie.getWindowToken(),0);
                        }else{
                            ie.canEdit=true;
                            ie.canShowSoftInput=true;
                            ivRW.setImageResource(R.drawable.ic_lead_pencil);
                        }
                    }
                }
            }else if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                CEditorPage cep=cet.cep;
                CIndentEditor cie=cep.cie;
                if(cie.canEdit){
                    cie.canEdit=false;
                    ivRW.setImageResource(R.drawable.ic_eye);
                    ma.imm.hideSoftInputFromWindow(cie.getWindowToken(),0);
                    ebi.setVisibility(GONE);
                }else{
                    cie.canEdit=true;
                    ivRW.setImageResource(R.drawable.ic_lead_pencil);
                    ebi.setVisibility(VISIBLE);
                }
            }
		}else if(v==ivUndo){//onClick
			if(tfNow instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)tfNow;
				ImageManipulationPage imp=imt.imp;
				imp.undo();
			}
		}else if(v==ivRedo){
			if(tfNow instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)tfNow;
				ImageManipulationPage imp=imt.imp;
				imp.redo();
			}
		}else if(v==ivMore){
            if(tfNow instanceof JavaEditorTab){
                try{
                JavaEditorTab jet=(JavaEditorTab)tfNow;
                if(jetm==null){jetm=new JavaEditorTab.Menu(ma);}
				jetm.show(jet,ivMore);
                }catch(Exception e){log.alert(e.toString());}
            }else if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                if(qsfc==null)qsfc=new QuerySettingsForCEditor(ma);
                qsfc.show(cet,ivMore);
            }else if(tfNow instanceof FileBrowserTab){
                FileBrowserTab fbt=(FileBrowserTab)tfNow;
                if(fbtm==null)fbtm=new FileBrowserTabMenu(ma);
				fbtm.show(fbt,ivMore);
            }else if(tfNow instanceof AppListTab){
                AppListTab alt=(AppListTab)tfNow;
                if(appListTabMenu==null)appListTabMenu=new AppListTabMenu(ma);
				appListTabMenu.show(alt,ivMore);
            }
        }else if(v==searchbar_quit){//onClick

            removeViewAt(titleIndex);
            addView(titlebar,titleIndex,titlebarlp);
            if(tfNow instanceof JavaEditorTab){
                JavaEditorTab jet=(JavaEditorTab)tfNow;
                jet.jep.jie.requestFocus();
            }
		}else if(v==ssi){
            
        }
	}
	@Override
	public boolean onLongClick(View v) {
		if(v==ivRefresh){//onLongClick
			if(tfNow instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)tfNow;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				if(fbp.dyn==1){
					IndentEditor ie=fbp.ie;
					if(ie.canEdit){
						try{
							FileReader fr=new FileReader(fbp.file);
							int i=fr.read();
							StringBuilder sb=new StringBuilder();
							while(i>=0){
								sb.append((char)i);
								i=fr.read();
							}
							String content=sb.toString();
							ie.letText(content.toCharArray());
							ie.invalidate();
							fbp.editorCanSave=false;
							fbt.setTextColor(fbt.textColorDefault);
							ivSave.setColorFilter(IconView.unable);
							ivSave.invalidate();
							ivRefresh.setColorFilter(IconView.unable);
							ivRefresh.invalidate();
							Toast.makeText(ma,"强行刷新",0).show();
						}catch(Exception e){
							log.alert(e.toString());
						}
					}
				}else if(fbp.dyn==2){
					HtmlIndentEditor ie=fbp.hie;
					if(ie.canEdit){
						try{
							FileReader fr=new FileReader(fbp.file);
							int i=fr.read();
							StringBuilder sb=new StringBuilder();
							while(i>=0){
								sb.append((char)i);
								i=fr.read();
							}
							String content=sb.toString();
							fbp.hie.letText(content.toCharArray());
							fbp.hie.invalidate();
							fbp.editorCanSave=false;
							fbt.setTextColor(fbt.textColorDefault);
							ivRefresh.setColorFilter(IconView.unable);
							ivRefresh.invalidate();
							ivSave.setColorFilter(IconView.unable);
							ivSave.invalidate();
							fbp.editorCanSave=false;
							Toast.makeText(ma,"强行刷新",0).show();
						}catch(Exception e){
							log.alert(e.toString());
						}
					}
				}
			}else if(tfNow instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)tfNow;
                JavaEditorPage jep=jet.jep;
                if(jep.jie.canEdit){
                    try{
                        FileReader fr=new FileReader(jet.jei.src);
                        int i=fr.read();
                        StringBuilder sb=new StringBuilder();
                        while(i>=0){
                            sb.append((char)i);
                            i=fr.read();
                        }
                        jep.jie.letText(sb);
                        jep.jie.invalidate();
                        jet.setTextColor(jet.textColorDefault);
                        jet.canSave=false;
                        ivRefresh.setColorFilter(IconView.unable);
                        ivRefresh.invalidate();
                        ivSave.setColorFilter(IconView.unable);
                        ivSave.invalidate();
                        Toast.makeText(ma,"强行刷新",0).show();
                    }catch(Exception e){
                        log.alert("On forced refresh text from file",e.toString());
                    }
                }else{
                    Toast.makeText(ma,"只读",0).show();
                }
			}else if(tfNow instanceof CEditorTab){
                CEditorTab cet=(CEditorTab)tfNow;
                CEditorPage cep=cet.cep;
                if(cep.cie.canEdit){
                    try{
                        FileReader fr=new FileReader(cet.ce.src);
                        StringBuilder sb=cep.cie.text;
                        sb.setLength(0);
                        int i=fr.read();
                        while(i>=0){
                            sb.append((char)i);
                            i=fr.read();
                        }
                        cep.cie.letText(sb);
                        cet.canSave=false;
                        cet.setTextColor(cet.textColorDefault);
                        ivRefresh.setColorFilter(IconView.unable);
                        ivRefresh.invalidate();
                        ivSave.setColorFilter(IconView.unable);
                        ivSave.invalidate();
                        Toast.makeText(ma,"强行刷新",0).show();
                    }catch(Exception e){
                        log.alert("On forced refresh text from file",e.toString());
                    }
                }else{
                    Toast.makeText(ma,"只读",0).show();
                }
            }
		}
		return true;
	}
	public static class Item extends TextView {
        public static int unenabledColor=0xff777777;
        public static int enabledColor=0xff000000;
		public Item(Context ctx) {
			super(ctx);
			setTypeface(Typeface.MONOSPACE);
			setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
			setTextColor(0xff000000);
			setGravity(Gravity.CENTER_VERTICAL);
			setPadding(5, 0, 0, 0);
			StateListDrawable sd=new StateListDrawable();
			sd.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(0xff777777));
			setBackgroundDrawable(sd);
		}

        @Override
        public void setEnabled(boolean enabled) {
            super.setEnabled(enabled);
            if(enabled){
                setTextColor(enabledColor);
            }else{
                setTextColor(unenabledColor);
            }
        }
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			Paint p=new Paint();
			p.setColor(MainActivity.CYAN);
			canvas.drawRect(0, canvas.getHeight() - borderWidth, canvas.getWidth(), canvas.getHeight(), p);
		}
	}
	public static class Pressed extends StateListDrawable{
		public Pressed(){
			addState(new int[]{android.R.attr.state_pressed},new ColorDrawable(0x77999999));
		}
	}
	public static class BorderDrawable extends ColorDrawable {
		boolean l=true,t=true,r=true,b=true;
		Paint border=new Paint();
		public BorderDrawable(){
			border.setColor(borderColor);
			border.setStyle(Paint.Style.FILL);
		}
		public BorderDrawable(boolean l,boolean t,boolean r,boolean b){
			this();
			this.l=l;
			this.t=t;
			this.r=r;
			this.b=b;
		}
		@Override
		public void draw(Canvas cvs) {
			int w=cvs.getWidth();
			int h=cvs.getHeight();
			cvs.drawColor(0xffffffff);
			cvs.drawRect(0, 0, borderWidth, h, border);
			cvs.drawRect(0, 0, w, borderWidth, border);
			cvs.drawRect(w - borderWidth, 0, w, h, border);
			cvs.drawRect(0,h-borderWidth,w,h,border);
		}
	}
	public class TabOnClick implements OnClickListener{
		@Override
		public void onClick(View v){
			if(tfNow==null){
			}else if(tfNow==v){
				return;
			}else{
				TabBar.Tab tfNow_=(TabBar.Tab)tfNow;
				tfNow_.letUnderline(false);
			}
			tfNow=v;
			if(v instanceof FileBrowserTab){
				FileBrowserTab fbt=(FileBrowserTab)v;
				FileBrowserPage fbp=fbt.fileBrowserPage;
				status.setVisibility(GONE);
				removeViewAt(titleIndex);
                addView(titlebar,titleIndex,titlebarlp);
				ivSearch.setVisibility(GONE);
				ivUndo.setVisibility(GONE);
				ivRedo.setVisibility(GONE);
				getChildAt(bottomIndex).setVisibility(GONE);
				fbt.letUnderline(true);
				if(fbp==null){
					fbp=new FileBrowserPage(ma);
					if(fbt.fbi==null){
						ArrayList<File> fs=new ArrayList<File>();
						ContentResolver mContentResolver=ma.getContentResolver();
						if(fbt.der==10){
							try{
								Cursor c = mContentResolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
								int columnIndexOrThrow_DATA = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
								while(c.moveToNext()){
									String path = c.getString(columnIndexOrThrow_DATA);
									File f=new File(path);
									fs.add(f);
								}
							}catch(Exception e){
								log.alert(e.toString());
							}
							File[] files=new File[fs.size()];
							fs.toArray(files);
							fbp.der=10;
							fbp.files=files;
							fbp.setWillShow(files);
							fbp.fn.setVisibility(GONE);
							fbp.toolsbar.setVisibility(GONE);
						}else if(fbt.der==20){
							try{
								Cursor c=mContentResolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,null,null,null,null);
								int columnIndex=c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
								while(c.moveToNext()){
									String path=c.getString(columnIndex);
									File f=new File(path);
									fs.add(f);
								}
							}catch(Exception e){
								log.alert("On acquire media images",e.toString());
							}
							File[] files=new File[fs.size()];
							fs.toArray(files);
							fbp.der=20;
							fbp.files=files;
							fbp.setWillShow(files);
							fbp.fn.setVisibility(GONE);
							fbp.toolsbar.setVisibility(GONE);
						}
					}else{
						fbp.fbi=fbt.fbi;
						fbp.home=fbt.fbi.home;
						fbp.letDir(fbp.home);
					}
					fbt.fileBrowserPage=fbp;
				}
				pageStub.removeViewAt(0);
				pageStub.addView(fbt.fileBrowserPage,0,pageLayoutParams);
				if(fbp.dlv.getVisibility()==VISIBLE){
					ebi.setVisibility(GONE);
                    ivSave.setVisibility(GONE);
                    ivRefresh.setVisibility(GONE);
                    ivInfo.setVisibility(GONE);
                    ivRW.setVisibility(GONE);
				}else if(fbp.hb!=null&&fbp.hb.getVisibility()==VISIBLE){
					ebi.setVisibility(GONE);
					ivSave.setVisibility(GONE);
					ivInfo.setVisibility(GONE);
					ivRW.setVisibility(GONE);
				}else if(fbp.ie!=null&&fbp.ie.getVisibility()==VISIBLE){
					ebi.setVisibility(VISIBLE);
                    ebi.to=fbp.ie;
                    ivSave.setVisibility(VISIBLE);
                    ivRefresh.setVisibility(VISIBLE);
                    
				}else if(fbp.hie!=null&&fbp.hie.getVisibility()==VISIBLE){
					ebi.setVisibility(VISIBLE);
                    ebi.to=fbp.hie;
				}else{
				}
                
				if(fbp.der==0){//normal browse files
                    
                    if(fbp.dyn==0){
                        if(fbp.dlv.getVisibility()==VISIBLE){
                            ivInfo.setVisibility(GONE);
                            ivInto.setVisibility(GONE);
                            ivQuit.setVisibility(GONE);
                            ivRefresh.setVisibility(GONE);
                            ivSave.setVisibility(GONE);
                            ivRW.setVisibility(GONE);
                            ivPR.setVisibility(GONE);
                        }
                    }else if(fbp.dyn==1){
                        if(fbp.ie.getVisibility()==VISIBLE){
                            ivInfo.setVisibility(VISIBLE);
                            ivRefresh.setVisibility(VISIBLE);
                            ivSave.setVisibility(VISIBLE);
                            ivRW.setVisibility(VISIBLE);
                            ivQuit.setVisibility(VISIBLE);
                            ivInto.setVisibility(GONE);
                            ebi.setVisibility(VISIBLE);
                            if(fbp.editorCanSave){
                                ivSave.setColorFilter(null);
                                ivSave.invalidate();
                                ivRefresh.setColorFilter(null);
                                ivRefresh.invalidate();
                            }else{
                                ivSave.setColorFilter(IconView.unable);
                                ivSave.invalidate();
                                ivRefresh.setColorFilter(IconView.unable);
                                ivRefresh.invalidate();
                            }
                            if(fbp.ie.canEdit){
                                ivRW.setImageResource(R.drawable.ic_lead_pencil);
                            }else{
                                ivRW.setImageResource(R.drawable.ic_eye);
                            }
                        }else{
                            ivInto.setVisibility(VISIBLE);
                            ivQuit.setVisibility(GONE);
                        }
                    }else if(fbp.dyn==3){
                        if(fbp.dlv.getVisibility()==VISIBLE){
                            ivQuit.setVisibility(GONE);
                            ivInto.setVisibility(VISIBLE);
                        }else if(fbp.hb.getVisibility()==VISIBLE){
                            ivQuit.setVisibility(VISIBLE);
                            ivInto.setVisibility(GONE);
                        }
                    }else if(fbp.dyn==4){
                        if(fbp.hie.getVisibility()==VISIBLE){
                            ivInfo.setVisibility(VISIBLE);
                            ivRefresh.setVisibility(VISIBLE);
                            ivSave.setVisibility(VISIBLE);
                            ivRW.setVisibility(VISIBLE);
                            ivPR.setVisibility(VISIBLE);
                            ebi.setVisibility(VISIBLE);
                        }else if(fbp.dlv.getVisibility()==VISIBLE){
                            ivInfo.setVisibility(GONE);
                            ivInto.setVisibility(VISIBLE);
                            ivQuit.setVisibility(GONE);
                            ivRefresh.setVisibility(GONE);
                            ivSave.setVisibility(GONE);
                            ivRW.setVisibility(GONE);
                            ivPR.setVisibility(GONE);
                        }
                    }
					
				}else if(fbp.der==10){
					fbp.fn.setVisibility(GONE);
					fbp.toolsbar.setVisibility(GONE);
					if(fbp.dlv.getVisibility()==VISIBLE){
						ivInfo.setVisibility(GONE);
						ivInto.setVisibility(GONE);
						ivQuit.setVisibility(GONE);
						ivRefresh.setVisibility(GONE);
						ivSave.setVisibility(GONE);
						ivRW.setVisibility(GONE);
						ivPR.setVisibility(GONE);
					}
                    if(fbp.dyn==3){
                        if(fbp.hb!=null&&fbp.hb.getVisibility()==VISIBLE){
                            ivQuit.setVisibility(VISIBLE);
                            ivInto.setVisibility(GONE);
                        }else if(fbp.dlv.getVisibility()==VISIBLE){
                            ivQuit.setVisibility(GONE);
                            ivInto.setVisibility(VISIBLE);
                        }
                    }
				}
				if(fbt.fbi!=null){
					int i=ma.tabList.isExists(fbt.fbi);
					if(i>=0){
						ma.shr.edit().putInt("current_tab",i).apply();
					}
				}else{
					int i=ma.tabList.isExists(new TabData.MediaAudioBrowser());
					//log.alert("tab sequence is saved:"+i);
					if(i>=0){
						ma.shr.edit().putInt("current_tab",i).apply();
					}
				}
			}else if(v instanceof JavaEditorTab){
				JavaEditorTab jet=(JavaEditorTab)v;
				JavaEditorPage jep=jet.jep;
				if(jep==null){
					jep=new JavaEditorPage(jet);
					jet.jep=jep;
				}
				JavaIndentEditor jie=jep.jie;
				jet.letUnderline(true);
				removeViewAt(titleIndex);
                addView(titlebar,titleIndex,titlebarlp);
				ebi.setVisibility(VISIBLE);
                ebi.to=jie;
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(GONE);
				ivSave.setVisibility(VISIBLE);
				ivSearch.setVisibility(VISIBLE);
				ivRefresh.setVisibility(VISIBLE);
				ivUndo.setVisibility(GONE);
				ivRedo.setVisibility(GONE);
				pageStub.removeViewAt(0);
				pageStub.addView(jep,0,pageLayoutParams);
				if(jie.text==null){
					try{
                        jep.status.setText(jet.jei.src.getAbsolutePath());
						FileReader fr=new FileReader(jet.jei.src);
						int i=fr.read();
						StringBuilder sb=new StringBuilder();
						while(i>=0){
							sb.append((char)i);
							i=fr.read();
						}
						jie.letText(sb);
					}catch(Exception e){
						log.alert(e.toString());
					}
				}
				if(jet.canSave){
					ivSave.setColorFilter(null);
					ivRefresh.setColorFilter(null);
				}else{
					ivSave.setColorFilter(IconView.unable);
					ivRefresh.setColorFilter(IconView.unable);
				}
				int i=ma.tabList.isExists(jet.jei);
				if(i>=0){
					ma.shr.edit().putInt("current_tab",i).apply();
				}
			}else if(v instanceof AppListTab){
				AppListTab alt=(AppListTab)v;
				if(alt.ap==null)alt.ap=new AppListPage(ma);
				alt.letUnderline(true);
				pageStub.removeViewAt(0);
				pageStub.addView(alt.ap,0,pageLayoutParams);
				ebi.setVisibility(GONE);
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(GONE);
				ivSearch.setVisibility(GONE);
				ivUndo.setVisibility(GONE);
				ivRedo.setVisibility(GONE);
				removeViewAt(titleIndex);
                addView(titlebar,titleIndex,titlebarlp);
			}else if(v instanceof ArchiveListTab){
				ArchiveListTab alt=(ArchiveListTab)v;
				ArchiveListPage alp=alt.alp;
				alt.letUnderline(true);
				ebi.setVisibility(GONE);
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(GONE);
				ivUndo.setVisibility(GONE);
				ivRedo.setVisibility(GONE);
				ivSearch.setVisibility(GONE);
				removeViewAt(titleIndex);
                addView(titlebar,titleIndex,titlebarlp);
				if(alp==null){
					alt.alp=new ArchiveListPage(ma);
					alp=alt.alp;
					alp.src=alt.av.src;
				}
				pageStub.removeViewAt(0);
				pageStub.addView(alt.alp,0,pageLayoutParams);
			}else if(v instanceof ImageManipulationTab){
				ImageManipulationTab imt=(ImageManipulationTab)v;
				ImageManipulationPage imp=imt.imp;
				imt.letUnderline(true);
				ivInfo.setVisibility(VISIBLE);
				removeViewAt(titleIndex);
				addView(titlebar,titleIndex,titlebarlp);
				ebi.setVisibility(GONE);
				ivRW.setVisibility(VISIBLE);
				ivSave.setVisibility(VISIBLE);
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(GONE);
				ivUndo.setVisibility(VISIBLE);
				ivRedo.setVisibility(VISIBLE);
				if(imp==null){
					Bitmap image;
					try{
						image=BitmapFactory.decodeStream(new FileInputStream(imt.im.src));
						imp=new ImageManipulationPage(ma,image);
						imt.imp=imp;
					}catch(Exception e){
						log.alert("文件可能已损坏",e.toString());
						return;
					}
				}
				if(imp.canRefresh){
					ivRefresh.setColorFilter(null);
				}else{
					ivRefresh.setColorFilter(IconView.unable);
				}
				if(imp.canSave){
					ivSave.setColorFilter(null);
				}else{
					ivSave.setColorFilter(IconView.unable);
				}
				if(imp.undoable.isEmpty()){
					ivUndo.setColorFilter(IconView.unable);
				}else{
					ivUndo.setColorFilter(null);
				}
				if(imp.redoable.isEmpty()){
					ivRedo.setColorFilter(IconView.unable);
				}else{
					ivRedo.setColorFilter(null);
				}
				pageStub.removeViewAt(0);
				pageStub.addView(imp,0,pageLayoutParams);
			}else if(v instanceof CEditorTab){
				CEditorTab cet=(CEditorTab)v;
				CEditorPage cep=cet.cep;
				cet.letUnderline(true);
				ivChrome.setVisibility(GONE);
				ivInfo.setVisibility(VISIBLE);
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(GONE);
                ivPR.setVisibility(VISIBLE);
				ivRedo.setVisibility(GONE);
				ivRW.setVisibility(VISIBLE);
				ivSearch.setVisibility(VISIBLE);
				ivUndo.setVisibility(GONE);
				removeViewAt(titleIndex);
				addView(titlebar,titleIndex,titlebarlp);
				removeViewAt(bottomIndex);
				addView(ebi,bottomIndex,bottombarlp);
				if(cep==null){
					cep=new CEditorPage(ma);
					cet.cep=cep;
					try{
						FileReader fr=new FileReader(cet.ce.src);
						StringBuilder sb=new StringBuilder((int)cet.ce.src.length()/2+1);
						int i=fr.read();
						while(i>=0){
							sb.append((char)i);
							i=fr.read();
						}
						cep.cie.letText(sb);
					}catch(Exception e){
						log.alert("On read c source file",e.toString());
					}
				}
				ebi.setVisibility(VISIBLE);
				ebi.to=cet.cep.cie;
				if(cet.canSave){
					ivRefresh.setColorFilter(null);
					ivSave.setColorFilter(null);
				}else{
					ivRefresh.setColorFilter(IconView.unable);
					ivRefresh.setColorFilter(IconView.unable);
				}
                if(cep.cie.canEdit){
                    ivRW.setImageResource(R.drawable.ic_lead_pencil);
                }else{
                    ivRW.setImageResource(R.drawable.ic_eye);
                }
				ivRefresh.setVisibility(VISIBLE);
				ivSave.setVisibility(VISIBLE);
				pageStub.removeViewAt(0);
				pageStub.addView(cep,0,pageLayoutParams);
			}else{//maybe v==null
				ma.shr.edit().putInt("current_tab",-1).apply();
				pageStub.removeViewAt(0);
				pageStub.addView(defaultPage,0,pageLayoutParams);
				ivUndo.setVisibility(GONE);
				ivRedo.setVisibility(GONE);
				ivQuit.setVisibility(GONE);
				ivInto.setVisibility(GONE);
				ivRW.setVisibility(GONE);
				ivInfo.setVisibility(GONE);
				ivSave.setVisibility(GONE);
				ivRefresh.setVisibility(GONE);
				ivPR.setVisibility(GONE);
				ivSearch.setVisibility(GONE);
				ebi.setVisibility(GONE);
				removeViewAt(titleIndex);
                addView(titlebar,titleIndex,titlebarlp);
			}
		}
	}
}
